How to use Python to read the physical address(MAC ID) [closed]

Posted by getjoefree on Super User See other posts from Super User or by getjoefree
Published on 2012-07-07T02:05:05Z Indexed on 2012/07/07 3:18 UTC
Read the original article Hit count: 443

Filed under:
|

I want to read the physical address of the NIC model, i can get the results that i want to with SED.EXE before, but SED.EXE does not support my environment but Python ok, who have the means to do it.

The general situation (not plug the network cable, it is impossible to obtain IP address):

Ethernet adapter:
Connection-specific DNS Suffix.: Chianet
Description ...........: Marvell Yukon 88E8040 PCI-E Fast Ethernet Controller
Physical Address .........: A4-BA-DB-9D-1E-8E
Dhcp Enabled ...........: Yes
Autoconfiguration Enabled ....: Yes

Ethernet adapter 3:
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : Dell Wireless 1510 Wireless-N WLAN Mini-Card
Physical Address. . . . . . . . . : 00-23-4D-D9-C0-28

The description of the NIC different, we can use this to fetch the corresponding physical address, base on Physical Address does not work, because the computer with the WLAN Card, I want to use Python to read my computer the card information and after Python handles an output file, output file format: SET MAC = A4BADB9D1E8E

and sed format:

ipconfig -all|sed -nrf getmac.sed | sed -e "s/-//g" > WINMAC.BAT
getmac.sed:
/Marvell Yukon 88E8040/ {
n;
s/.*: ([-0-9A-F]+)/set winmac=\1/p;

}

© Super User or respective owner

Related posts about python

Related posts about sed